@import 'mixins/form';
@import 'mixins/size';

@include b(input) {
  @include component-in-form('#{&}:not(#{&}--number)') {
    width: 100%;
  }
  @include component-in-form('#{&}--number') {
    max-width: 100%;
  }

  display: inline-flex;
  align-items: center;
  height: var(--#{$rd-prefix}size);
  padding: 0 calc(var(--#{$rd-prefix}horizontal-space-size) - 1px);
  color: var(--#{$rd-prefix}text-color);
  vertical-align: top;
  background-color: var(--#{$rd-prefix}background-color-input);
  border: 1px solid var(--#{$rd-prefix}color-border);
  border-radius: var(--#{$rd-prefix}border-radius);
  transition: border-color var(--#{$rd-prefix}animation-duration-base) linear;

  &:hover {
    border-color: var(--#{$rd-prefix}color-primary-lighter);
  }

  &[data-form-invalid-warning='true'] {
    border-color: var(--#{$rd-prefix}color-warning) !important;

    .#{$B}__input {
      caret-color: var(--#{$rd-prefix}color-warning) !important;
    }
  }

  &[data-form-invalid-error='true'] {
    border-color: var(--#{$rd-prefix}color-danger) !important;

    .#{$B}__input {
      caret-color: var(--#{$rd-prefix}color-danger) !important;
    }
  }

  @include component-size;

  @include when(disabled) {
    color: var(--#{$rd-prefix}color-disabled);
    pointer-events: none;
    background-color: var(--#{$rd-prefix}background-color-disabled);
  }

  @include when(focus) {
    border-color: var(--#{$rd-prefix}color-primary-lighter);
  }

  @include m(button-right) {
    padding-right: 0;
  }

  @include e(input) {
    @include utils-input;

    display: inline-block;
    flex-grow: 1;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0;
    margin: 0;
    color: inherit;
    background-color: transparent;
    border: none;

    &[type='number'] {
      appearance: textfield; /* Firefox */

      &::-webkit-outer-spin-button,
      &::-webkit-inner-spin-button {
        margin: 0; /* <-- Apparently some margin are still there even though it's hidden */

        /* display: none; <- Crashes Chrome on hover */
        appearance: none;
      }
    }

    &::placeholder {
      color: $rd-placeholder-color;
    }

    &:disabled::placeholder {
      color: $rd-placeholder-disabled-color;
    }
  }

  @include e(prefix) {
    flex-shrink: 0;
    margin-right: 4px;
  }

  @include e(suffix) {
    flex-shrink: 0;
    margin-left: 4px;
  }

  @include e(clear) {
    flex-shrink: 0;
    margin: 0 0 0 4px;
    font-size: 0.9em;
    color: var(--#{$rd-prefix}color-icon-decorator);
    cursor: pointer;
    transition: color var(--#{$rd-prefix}animation-duration-base) linear, opacity var(--#{$rd-prefix}animation-duration-fast) linear;

    &:hover,
    &:focus {
      color: var(--#{$rd-prefix}color-primary-lighter);
    }

    &:active {
      color: var(--#{$rd-prefix}color-primary-darker);
    }
  }

  @include e(password) {
    flex-shrink: 0;
    padding: 0;
    margin: 0 0 0 4px;
    font-size: 0.9em;
    color: var(--#{$rd-prefix}color-icon-decorator);
    cursor: pointer;
    transition: color var(--#{$rd-prefix}animation-duration-base) linear;

    &:hover,
    &:focus {
      color: var(--#{$rd-prefix}color-primary-lighter);
    }

    &:active {
      color: var(--#{$rd-prefix}color-primary-darker);
    }
  }

  @include e(number-container) {
    display: inline-flex;
    flex-direction: column;
    height: 100%;
    margin-left: 4px;
    font-size: 0.9em;
  }

  @include e(number) {
    display: inline-flex;
    flex-grow: 1;
    align-items: center;
    justify-content: center;
    width: 24px;
    color: var(--#{$rd-prefix}color-icon-decorator);
    cursor: pointer;
    transition: color var(--#{$rd-prefix}animation-duration-base) linear,
      background-color var(--#{$rd-prefix}animation-duration-base) linear;

    &:hover,
    &:focus {
      color: var(--#{$rd-prefix}color-primary-lighter);
      background-color: var(--#{$rd-prefix}background-color-primary-hover);
    }

    &:active {
      color: var(--#{$rd-prefix}color-primary-darker);
      background-color: var(--#{$rd-prefix}background-color-primary);
    }
  }
}
